/**
* Created by Administrator on 2025/5/7.
* */
#include "AppDelegate.h"
#include "GlobalParameters.h"
#include <string>
#include "AIPC/AIPC.h"
#include "MyDeviceReader/MyDeviceReader.h"
#include "CudaMTI/CudaMTI.h"
#include "AICFAR/AICFAR.h"
#include "AIMTD/AIMTD.h"
#include "Spot/Spot.h"
#include "MyDeviceWriter_1/MyDeviceWriter_1.h"
#include "Track/Track.h"
#include "MyDeviceWriter_2/MyDeviceWriter_2.h"
#include "AIPCMonitor/AIPCMonitor.h"
#include "MyDeviceWriter/MyDeviceWriter.h"
#include "AICFARMonitor/AICFARMonitor.h"
#include "MyDeviceReader_1/MyDeviceReader_1.h"
#include "MyDeviceReader_2/MyDeviceReader_2.h"
#include "AINodeInferController/AINodeInferController.h"
#include "EthernetReader.h"
#include "EthernetWriter.h"

float inferTime = INFER_TIME1;

void AppDelegate::onConfigure(device_config_t *config){
    config->calculationPoolSize=8;
    config->globalParametersInstance = GlobalParameters::shareInstance();
    config->deviceId=3;
    config->servicePort=55261;
    config->ip="192.168.1.115";
    config->userVersion="1.0";
}

void AppDelegate::onStart(){
    REGISTER_RUNTIME_LOADED_CLASSES(AIPC,MyDeviceReader,CudaMTI,AICFAR,AIMTD,MyDeviceWriter,Spot,MyDeviceWriter_1,Track,MyDeviceWriter_2);
    REGISTER_RUNTIME_LOADED_CLASSES(AIPCMonitor,MyDeviceReader_1,AICFARMonitor,MyDeviceReader_2,AINodeInferController);
    auto aiPC = new AIPC();
    auto cudaMTI = new CudaMTI();
    auto aiCFAR = new AICFAR();
    auto aiMTD = new AIMTD();
    auto sopt = new Spot();
    auto track = new Track();
    auto aiPCMonitor = new AIPCMonitor();
    auto aiCFARMonitor = new AICFARMonitor();
    auto aiNodeInferController = new AINodeInferController();

    auto radarlabReader = new MyDeviceReader();
    radarlabReader->addTaskModule(aiPC,0,1024);
    radarlabReader->addTaskModule(aiNodeInferController,0,1024);

    auto radarlabReader_4 = new MyDeviceReader_1();
    radarlabReader_4->addTaskModule(aiPCMonitor,0,1024);

    auto radarlabReader_5 = new MyDeviceReader_2();
    radarlabReader_5->addTaskModule(aiCFARMonitor,0,1024);

    auto radarlabReader_1 = new MyDeviceReader();
    radarlabReader_1->addTaskModule(aiPC,1,1024);

    auto radarlabReader_2 = new EthernetReader(TCP,6675);
    radarlabReader_2->addTaskModule(aiNodeInferController,1,1024);

    auto radarlabReader_3 = new EthernetReader(TCP,6676);
    radarlabReader_3->addTaskModule(aiNodeInferController,2,1024);

    aiPC->addOutput(0,0,cudaMTI,1024);
    cudaMTI->addOutput(0,0,aiMTD,1024);
    aiMTD->addOutput(0,0,aiCFAR,1024);
    aiCFAR->addOutput(0,0,sopt,1024);
    sopt->addOutput(0,0,track,1024);
    aiPC->addOutput(1,1,aiPCMonitor,1024);
    aiCFAR->addOutput(1,1,aiCFARMonitor,1024);

    aiNodeInferController->setLaunchPolicy(LaunchMode_OR,LaunchCondition());

    auto radarlabWriter_1 = new MyDeviceWriter_1();
    sopt->addDeviceWriter(1,radarlabWriter_1,1024);

    auto radarlabWriter = new MyDeviceWriter_2();
    track->addDeviceWriter(0,radarlabWriter,1024);

    auto radarlabWriter_2 = new MyDeviceWriter_2();
    track->addDeviceWriter(1,radarlabWriter_2,1024);

    auto radarlabWriter_5 = new MyDeviceWriter();
    aiCFARMonitor->addDeviceWriter(0,radarlabWriter_5,1024);

    auto radarlabWriter_2_1 = new MyDeviceWriter();
    aiMTD->addDeviceWriter(0,radarlabWriter_2_1,1024);

    auto radarlabWriter_3 = new MyDeviceWriter();
    aiPCMonitor->addDeviceWriter(0,radarlabWriter_3,1024);

    auto radarlabWriter_4 = new MyDeviceWriter();
    aiNodeInferController->addDeviceWriter(0,radarlabWriter_4,1024);

    auto radarlabWriter_6 = new EthernetWriter(TCP,"192.168.1.115",6679,true);
    aiCFARMonitor->addDeviceWriter(1,radarlabWriter_6,1024);
    REGISTER_INSTANCES(aiPC,radarlabReader,radarlabReader_1,cudaMTI,aiCFAR,aiMTD,radarlabWriter_2_1,sopt,radarlabWriter_1,track);
    REGISTER_INSTANCES(radarlabWriter,radarlabWriter_2,aiPCMonitor,radarlabReader_4,radarlabWriter_3,aiCFARMonitor,radarlabReader_5,radarlabWriter_5,radarlabWriter_6,aiNodeInferController);
    REGISTER_INSTANCES(radarlabReader_2,radarlabReader_3,radarlabWriter_4);
}
